package com.usooft.metaTalent.core.base.log;

import com.usooft.metaTalent.core.base.config.LogeConfig;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.ArrayUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Component;

@Aspect
@Component
@EnableConfigurationProperties(LogeConfig.class)
@RequiredArgsConstructor
public class LogAOP {
    private final LogeConfig logeConfig;

    @Around("@annotation(col)")
    public Object aroundAdvice(ProceedingJoinPoint proceedingJoinPoint, ConditionalOnLogType col) throws Throwable {
        // 判断当前方法是否执行
        if (!ArrayUtils.contains(logeConfig.getType(), col.value()) || logeConfig.isShowLog()) {
            return null;
        }
        return proceedingJoinPoint.proceed();
    }

}
